/*
	Copyright (c) 2004-2009, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if (!dojo._hasResource["dojox.gfx.MoverLimited"]) {
	dojo._hasResource["dojox.gfx.MoverLimited"] = true;
	dojo.provide("dojox.gfx.MoverLimited");
	dojo.declare("dojox.gfx.MoverLimited", null, {
		constructor: function(_1, e, _3){
			this.shape = _1;
			this.lastX = e.clientX;
			
			var h = this.host = _3, d = document, _6 = dojo.connect(d, "onmousemove", this, "onFirstMove");
			this.events = [dojo.connect(d, "onmousemove", this, "onMouseMove"), dojo.connect(d, "onmouseup", this, "destroy"), dojo.connect(d, "ondragstart", dojo, "stopEvent"), dojo.connect(d, "onselectstart", dojo, "stopEvent"), _6];
			if (h && h.onMoveStart) {
				h.onMoveStart(this);
			}
		},
		onMouseMove: function(e){
			var x = e.clientX;
			this.host.onMove(this, {
				dx: x - this.lastX
			});
			
			var ch = this.host.shape.parent._parent.parentNode.id.replace("div","");
			var index = this.host.shape.rawNode.id.replace(ch+"mark","")-1;
			
			var chObj = document.getElementById(ch+ "obj");
			chObj.positions[index] = chObj.positions[index] + x - this.lastX;//chImage left = 255px + marker width/2 = 4px
			chObj.regions();
			this.lastX = x;
			dojo.stopEvent(e);
		},
		onFirstMove: function(){
			this.host.onFirstMove(this);
			dojo.disconnect(this.events.pop());
		},
		destroy: function(){
			dojo.forEach(this.events, dojo.disconnect);
			var h = this.host;
			if (h && h.onMoveStop) {
				h.onMoveStop(this);
			}
			this.events = this.shape = null;
		}
	});
	
}
